﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class PhieuNhapHang : Form
    {
        public PhieuNhapHang()
        {
            InitializeComponent();
        }

        private void PhieuNhapHang_Load(object sender, EventArgs e)
        {
            HienThiDanhSach();
        }

        private void HienThiDanhSach()
        {
            List<PhieuNhapHangDTO> dtoDS = new List<PhieuNhapHangDTO>();
            PhieuNhapHangBUS bus = new PhieuNhapHangBUS();
            dtoDS = bus.HienThi();
            gridViewPhieuNhap.Rows.Clear();
            for (int i = 0; i <= dtoDS.Count - 1; i++)
            {
                gridViewPhieuNhap.Rows.Add(dtoDS[i].MAPN, dtoDS[i].MANCC, dtoDS[i].NGAYNHAP, dtoDS[i].TONGTIEN);
            }
        }

        private void btnThem_Click(object sender, EventArgs e)
        {           
            ChiTietPhieuNhap frm = new ChiTietPhieuNhap();            
            frm._kq = 1;
            frm.ShowDialog();
        }

        private void gridViewPhieuNhap_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                ChiTietPhieuNhap frm = new ChiTietPhieuNhap();
                frm._mapn = gridViewPhieuNhap.CurrentRow.Cells[0].Value.ToString();
                frm._mancc = gridViewPhieuNhap.CurrentRow.Cells[1].Value.ToString();
                frm._ngaynhap = DateTime.Parse(gridViewPhieuNhap.CurrentRow.Cells[2].Value.ToString());
            }
            catch
            {
                                
            }
            
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                ChiTietPhieuNhap frm = new ChiTietPhieuNhap();
                frm._mapn = gridViewPhieuNhap.CurrentRow.Cells[0].Value.ToString();
                frm._mancc = gridViewPhieuNhap.CurrentRow.Cells[1].Value.ToString();
                frm._ngaynhap = DateTime.Parse(gridViewPhieuNhap.CurrentRow.Cells[2].Value.ToString());
                frm._kq = 2;
                frm.ShowDialog();
            }
            catch
            {
                MessageBox.Show("Cảm Phiền Chọn Dữ Liệu");
            }
            
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            try
            {
                ChiTietPhieuNhap frm = new ChiTietPhieuNhap();
                frm._mapn = gridViewPhieuNhap.CurrentRow.Cells[0].Value.ToString();
                frm._mancc = gridViewPhieuNhap.CurrentRow.Cells[1].Value.ToString();
                frm._ngaynhap = DateTime.Parse(gridViewPhieuNhap.CurrentRow.Cells[2].Value.ToString());
                frm._kq = 3;
                frm.ShowDialog();
            }
            catch
            {
                MessageBox.Show("Cảm Phiền Chọn Dữ Liệu");
            }
            
        }

        private void btnLamMoi_Click(object sender, EventArgs e)
        {
            HienThiDanhSach();
        }
    }
}
